<?php

/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the Closure to execute when that URI is requested.
|
*/


/*
|-------------------------------------------------------------------------
|   Public Application
|-------------------------------------------------------------------------
|
|   Users Application Routes
|
*/

Route::get('test', function(){
    return View::make('test');
});

Route::get  ('hash', function(){
    return View::make('hash');
});

Route::get  ('/',          'HomeController@showWelcome');
Route::get  ('choose',     'HomeController@showWelcome');
Route::get  ('newuser',    'UserController@newUser');
Route::post ('newuser/{mode}',    'UserController@create');
Route::get  ('olduser',    'UserController@login');
Route::post ('olduser',    'UserController@olduser');
Route::get  ('welcome',    'ServiceController@displayServices');
Route::post ('welcome',    'ServiceController@selectServices');
Route::post ('endRequest', 'UserController@endRequest');
Route::get  ('uqueue', function(){
    return View::make('kir.uqueue')->with('title', 'Cola de Clientes');
});

Route::get  ('opelogin', function(){
    return View::make('kir.opelogin')->with('title', 'Inicio de Sesión de Operador');
});

Route::post ('opelogin', function(){
    return Redirect::to('uqueue');
});

/* ---------------------------------------------------------------------- */


/*}
|-------------------------------------------------------------------------
|   Administrator Application
|-------------------------------------------------------------------------
|
|   Administrator Application Routes
|
*/

Route::get  ('login', 'AdminController@welcome');
Route::post ('login', 'AdminController@login');

Route::group(array('prefix' => 'admin', 'before' => 'auth'), function()
{
    Route::post ('registerAdmin',    'AdminController@create');
    Route::post ('registerUser/{mode}',     'UserController@create');
    Route::post ('registerOper',     'OperatorController@register');
    Route::post ('registerServ',     'ServiceController@register');
    Route::post ('registerProd',     'ProductController@register');
    Route::post ('updateAdmin/{id}', 'AdminController@update');
    Route::post ('updateUser/{id}',  'UserController@update');
    Route::post ('updateOper/{id}',  'OperatorController@update');
    Route::post ('updateServ/{id}',  'ServiceController@update');
    Route::post ('updateProd/{id}',  'ProductController@update');
    Route::post ('delete',           'AdminController@delete');
    Route::post ('changepass/{id}',  'AdminController@changepass');
    Route::get  ('viewAdmin/{id}',   'AdminController@view');
    Route::get  ('viewUser/{id}',    'UserController@view');
    Route::get  ('viewOper/{id}',    'OperatorController@view');
    Route::get  ('viewServ/{id}',    'ServiceController@view');
    Route::get  ('viewProd/{id}',    'ProductController@view');
    Route::get  ('list/{list}',      'AdminController@listing');
    Route::get  ('create/{name}',    'AdminController@creating');
    Route::get  ('edit/{name}/{id}', 'AdminController@editing');
    Route::get  ('changepass/{id}',  'AdminController@viewchangepass');
    Route::get  ('pdf', function(){
        $html = '<html><body>'
            . '<p>Put your html here, or generate it with your favourite '
            . 'templating system.</p>'
            . '</body></html>';
        return PDF::load($html, 'A4', 'portrait')->show();
    });
    Route::get  ('code', function(){
        return View::make('admin.code')->with('title', 'code')->with('active', 0);
    });
});

Route::get('admin', array('before' => 'auth', 'do' => function() {
    return View::make('admin.admin')->with('title', 'Bienvenido')->with('active', 0);
}));

Route::filter('auth', function()
{
    if (Auth::guest()) return Redirect::to('login');
});

Route::get('logout', function()
{
    Auth::logout();
    return Redirect::to('login');
});

